package com.web.exiaodao.remote.controller;
import com.web.exiaodao.remote.service.ApiServiceNurseTrainingService;
import com.web.exiaodao.remote.vo.ServiceNurseTrainingVo;
import com.web.webstart.base.constant.XaConstant;
import com.web.webstart.base.controller.BaseController;
import com.web.webstart.base.exception.BusinessException;
import com.web.webstart.base.util.jpa.WebUitl;
import com.web.webstart.base.util.result.XaResult;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Title: ApiNurseTrainingController.java
 * @Package com.web.exiaodao.remote.controller
 * @Description: 服务-护理培训/培训义工信息接口
 * @author zhanglin
 * @date 2016-11-03 18:26:49
 * @version V1.0
 */
@Api(value = "ServiceNurseTraining", description = "服务-护理培训/培训义工接口", position = 10)
@Controller
@RequestMapping("/api/nurseTraining")
public class ApiServiceNurseTrainingController extends BaseController {

	private static final Logger LOGGER = Logger.getLogger(ApiServiceNurseTrainingController.class);

	@Autowired
	private ApiServiceNurseTrainingService nurseTrainingService;
	
	/**
	 * @Title: findNurseTrainingList
	 * @Description: 查询所有服务-护理培训/培训义工信息
	 * @return    
	 */
	@ApiOperation(value="查询所有服务-护理培训/培训义工",notes="查询所有服务-护理培训/培训义工信息,当返回的code=1时，取出object进行显示,存放为数组对象")
	@ResponseBody
	@RequestMapping(value="findNurseTrainingList",method=RequestMethod.POST)
	public XaResult<List<ServiceNurseTrainingVo>> findNurseTrainingList(
		@ApiParam("页号,字段名:nextPage,默认0,从第0页开始") @RequestParam(defaultValue = "0") Integer nextPage,
		@ApiParam("页长,字段名:pageSize,默认10") @RequestParam(defaultValue = "10") Integer pageSize
	) throws BusinessException{
        XaResult<List<ServiceNurseTrainingVo>> xr = new  XaResult<List<ServiceNurseTrainingVo>>();
		Pageable pageable = WebUitl.buildPageRequest(nextPage, pageSize, "[{property:'sort',direction:'ASC'},{property:'clickCont',direction:'DESC'},{property:'createTime',direction:'DESC'}]");
		Map<String , Object> filterParams =  WebUitl.getParametersStartingWith("{}", "search_");
		try{
				return nurseTrainingService.findListEQStatusByFilter(XaConstant.Status.valid, filterParams, pageable);
		}catch(Exception e){
			if (e instanceof BusinessException) {
				xr.error(e.getMessage());
			} else  {
				xr.error(XaConstant.Message.error);
			}
			LOGGER.error(XaConstant.Message.error, new Throwable(e));
		}
		return xr;
	}

	
	/**
	 * @Title: findNurseTrainingById
	 * @Description: 根据ID查找单条实体
	 * //@param modelId
	 * @return    
	 */
	@ApiOperation(value="服务-护理培训/培训义工详情",notes="查询服务-护理培训/培训义工详细信息,当返回的code=1时，取出object进行显示,存放为单体对象")
	@ResponseBody
	@RequestMapping(value="findNurseTrainingById",method=RequestMethod.POST)
	public XaResult<ServiceNurseTrainingVo> findNurseTrainingById(
		@ApiParam("编号,字段名:id,必填") @RequestParam(value = "id") Long id
	) throws BusinessException{
		XaResult<ServiceNurseTrainingVo> xr = new XaResult<ServiceNurseTrainingVo>();
		return nurseTrainingService.findOne(id);
	}

}

